package com.ruoyi.system.excelImport.pangxie.service.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.V2.financial.service.IFinanceService;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoMapper;
import com.ruoyi.system.V2.goodInfo.service.IGoodsInfoService;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.excelImport.pangxie.pxExcel.*;
import com.ruoyi.system.excelImport.pangxie.service.PangXieImportService;
import com.ruoyi.system.excelImport.pangxie.utils.PANGXIEExcelUtils;
import com.ruoyi.system.excelImport.pangxie.utils.PangXieUtil;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.model.domain.ArtRec;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.GoodsInfo;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.thread.StartInter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @other pzz
 * @data 2024/8/3
 * @apiNote
 */
@Slf4j
@Service
public class PangXieImportServiceImpl implements PangXieImportService {
    @Resource
    private ArtRecMapper artRecMapper;
    @Autowired
    private StartInter startInter;
    @Autowired
    private PANGXIEExcelUtils pangxieExcelUtils;
    @Autowired
    private CommonApi commonApi;
    @Autowired
    private GoodsInfoMapper goodsInfoMapper;

    @Autowired
    private IGameAttributeService gameAttributeService;


    @Override
    public void impostPX(List<GoodsInfo> dataList, String gameName, SalePartner salePartner) {
        List<GoodsInfoAndAttrValueDto> list = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(dataList)) {
            List<Long> collect = dataList.stream().map(s -> s.getId()).collect(Collectors.toList());
            list = goodsInfoMapper.selectGoodsInfoAndAttrValueByIds(collect);
        } else {
            return;
        }
        JSONObject response = new JSONObject();
        for (GoodsInfoAndAttrValueDto dto : list) {
            // 加价
            BigDecimal bigDecimal = commonApi.addPrice(dto.getPrice(), salePartner.getSeleep());
            commonApi.setPrice(bigDecimal, dto.getId(), salePartner);
            dto.setPrice(bigDecimal);
        }

        if (StringUtils.equals("英雄联盟", gameName)) {
            response = lolExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("王者荣耀", gameName)) {
            response = wzryExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("永劫无间", gameName)) {
            response = yjwjExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("英雄联盟(手游)", gameName)) {
            response = lolmExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("枪战王者", gameName)) {
            response = qzwzExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("无畏契约", gameName)) {
            response = wwqyExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("永劫无间手游", gameName)) {
            response = yjwjmExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("暗区突围", gameName)) {
            response = aqtwExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("三角洲行动", gameName)) {
            response = sjzxdExcelPushList(list, gameName, salePartner);
        } else if (StringUtils.equals("使命召唤手游", gameName)) {
            response = smzhMExcelPushList(list, gameName, salePartner);
        } else {
            return;
        }
        JSONObject gameMap = response.getJSONObject("gameMap");  // 每个商品的请求参数

        Map<String, List<JSONObject>> collectMap = new HashMap<>();

        List<Long> importIdsCollect = dataList.stream().map(s -> s.getId()).collect(Collectors.toList());
        List<JSONObject> listPX = pangxieExcelUtils.getListPX(gameName, salePartner, importIdsCollect);
        if (CollectionUtils.isNotEmpty(listPX)) {
            collectMap = listPX.stream().filter(s -> StringUtils.isNotEmpty(s.getString("merchantProductUniqueNo"))).collect(Collectors.groupingBy(s -> s.getString("merchantProductUniqueNo")));
        }

        for (GoodsInfoAndAttrValueDto dto : list) {
            Map<String, Object> result = new HashMap<>();
            if (CollectionUtils.isNotEmpty(listPX)) {  // 待审核列表不为空
                if (StringUtils.isNotEmpty(collectMap.get(dto.getId().toString()))) {  // 并且待审核列表有这个商品id   证明添加成功
                    ArtRec artRecreq = new ArtRec();
                    artRecreq.setConfig(salePartner.getId());
                    artRecreq.setAccountId(dto.getId());
                    List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
                    if (CollectionUtils.isEmpty(artRecs)) {
                        artRecreq.setAccountId(dto.getId());
                        artRecreq.setCreateId(dto.getCreateId());
                        artRecreq.setType(LCConstant.interAdd);
                        artRecreq.setConfig(salePartner.getId());
                        artRecreq.setSaleCode(salePartner.getSaleName());
                        JSONObject data = collectMap.get(String.valueOf(dto.getId())).get(0);
                        artRecreq.setOutid(
                                data.getString("productId") + "-" + data.getString("uniqueNo")
                        );
                        artRecMapper.insertArtRec(artRecreq);
                    }
                    result.put("code", "200");
                } else {
                    result.put("code", "500");  // 待审核没有这个id
                }
            } else {
                result.put("code", "500");  // 待审核列表一个都没有
            }
            if (Objects.nonNull(gameMap) && Objects.nonNull(gameMap.getString(String.valueOf(dto.getId())))) {
                result.put("req", gameMap.getString(String.valueOf(dto.getId())));
            } else {
                result.put("req", JSONObject.toJSONString(dto));
            }
            response.remove("gameMap");
            result.put("res", response);
            result.put("msg", response.getString("message"));
            startInter.getOutRecAndInterRec(AjaxResult.success(result), salePartner.getSaleName(), salePartner, dto, null);
        }
    }

    public JSONObject lolExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<LOLExcelPush> resultList = new ArrayList<>();
        List<GameAttribute> attributes = gameAttributeService.selectGameAttributeByParentId(39493l);
        Map<Long, String> collectMap = attributes.stream().collect(Collectors.toMap(s -> s.getId(), s -> s.getFieldName()));
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            LOLExcelPush excelPush = new LOLExcelPush();
            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            excelPush.setYingdiId("");
            excelPush.setGroupName(goods.getGroupName());
            String f1 = collectMap.get(Long.valueOf(goods.getF1()));
            if (StringUtils.equals(f1, "可修改实名")) {
                excelPush.setShiming("可二次实名");
            } else {
                excelPush.setShiming("支持人脸包赔");
            }
            excelPush.setServerName(goods.getServerName());

            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject wzryExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        GameAttribute attribute = new GameAttribute();
        attribute.setGameId(2L);
        List<GameAttribute> gameAll = gameAttributeService.selectGameAttributeList(attribute);
        Map<Long, String> paramMap = gameAll.stream().filter(s -> StringUtils.isNotEmpty(s.getFieldName())).collect(Collectors.toMap(s -> s.getId(), s -> s.getFieldName()));

        List<WZRYExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            WZRYExcelPush excelPush = new WZRYExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            excelPush.setYingdiId(goods.getF17());

            String systemName = (goods.getSystemName() + goods.getCarrierName()).toLowerCase();
            if (StringUtils.equals("安卓qq", systemName)) {
                excelPush.setSystemName("安卓QQ");
            } else if (StringUtils.equals("安卓微信", systemName)) {
                excelPush.setSystemName("安卓微信");
                excelPush.setIsBingCD("无换绑CD");
            } else if (StringUtils.equals("苹果qq", systemName)) {
                excelPush.setSystemName("苹果QQ");
            } else if (StringUtils.equals("苹果微信", systemName)) {
                excelPush.setSystemName("苹果微信");
                excelPush.setIsBingCD("无换绑CD");
            }
            //0-不可二次实名
            //1-可二次实名
            //2-支持人脸包赔
            String f16 = paramMap.get(Long.valueOf(goods.getF16()));
            if (StringUtils.equals(f16, "可二次实名") || StringUtils.equals(f16, "已删实名")) {
                excelPush.setShiming("可二次实名");
            } else {
                excelPush.setShiming("支持人脸包赔");
            }
            //0-无防沉迷
            //1-有防沉迷
            excelPush.setFangchenmi("无防沉迷");

            excelPush.setPaiwei("可排位");


            String guizu = "无贵族等级";
            if (StringUtils.isNotEmpty(goods.getF2())) {
                String f2 = paramMap.get(Long.valueOf(goods.getF2()));
                if (f2.contains("V")) {
                    f2 = f2.replace("V", "贵族") + "级";
                }
                guizu = f2;
            }
            excelPush.setGuizudengji(guizu);
            //星元皮肤
            excelPush.setGuizujifen(goods.getF4());

            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject yjwjExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<YJWJExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            YJWJExcelPush excelPush = new YJWJExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");

            String groupName = goods.getGroupName();
            if (StringUtils.isNotEmpty(groupName)) {
                if (groupName.contains("Steam")) {
                    excelPush.setSystemName("Steam");
                } else if (groupName.contains("Epic")) {
                    excelPush.setSystemName("epic");
                } else {
                    excelPush.setSystemName("网易国服");
                }
            } else {
                excelPush.setSystemName("网易国服");
            }

            String serverName = goods.getServerName();
            if (serverName.contains("手机帐号")) {
                excelPush.setAccountType("手机账号");
            } else if (serverName.contains("邮箱帐号")) {
                excelPush.setAccountType("邮箱账号");
            } else {
                excelPush.setAccountType("国服");
            }

            if (StringUtils.isNotEmpty(goods.getF50())) {
                if (goods.getF50().equals("61261")) {
                    excelPush.setWyPayStatus("可注销");
                } else {
                    excelPush.setWyPayStatus("不可注销");
                }
            } else {
                excelPush.setWyPayStatus("不可注销");
            }
            if (StringUtils.equals(excelPush.getSystemName(), "网易国服")) {
                if (StringUtils.isNotEmpty(goods.getF54())) {
                    if ("63657".equals(goods.getF54())) {
                        excelPush.setHuanbanglengque("有冷却");
                    } else {
                        excelPush.setHuanbanglengque("无冷却");
                    }
                }
            } else {
                excelPush.setHuanbanglengque("有冷却");
            }
            excelPush.setGoodsId(String.valueOf(goods.getId()));
            excelPush.setGoodsIdCode(String.valueOf(goods.getId()));
            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;

    }

    public JSONObject lolmExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<LOLMExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            LOLMExcelPush excelPush = new LOLMExcelPush();
            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号
            excelPush.setYingdiId("");

            // 帐号类型
            String system = (goods.getSystemName() + goods.getCarrierName());
            excelPush.setAccountType(system);
            // 实名情况
            String f4 = goods.getF4();
            if (StringUtils.equals(f4, "53057") || StringUtils.equals(f4, "53059")) {
                excelPush.setShiming("可二次实名");
            } else {
                excelPush.setShiming("支持人脸包赔");
            }

            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject qzwzExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<GameAttribute> vipAttr = gameAttributeService.selectGameAttributeByParentId(41720l);
        List<QZWZExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {

            QZWZExcelPush excelPush = new QZWZExcelPush();
            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            String system = (goods.getSystemName() + goods.getCarrierName());

            excelPush.setSystemName(system);

            excelPush.setShiming("支持人脸包赔");
            String vip = "VIP1级";
            if (StringUtils.isNotEmpty(goods.getF10())) {
                for (GameAttribute attribute : vipAttr) {
                    if (Objects.equals(attribute.getId(), Long.valueOf(goods.getF10()))) {
                        vip = attribute.getFieldName().replace("V", "VIP") + "级";
                    }
                }
            }

            excelPush.setVipLv(vip);
            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject wwqyExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<WWQYExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {

            WWQYExcelPush excelPush = new WWQYExcelPush();
            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            //QQ：1，微信：2
            excelPush.setAccountType("QQ");
            //【实名情况】：（不可二次实名：0，可二次实名：1，支持人脸包赔：2）
            String f1 = goods.getF1();
            if (StringUtils.equals(f1, "58982")) {
                excelPush.setShiming("可二次实名");
            } else if (StringUtils.equals(f1, "58983")) {
                excelPush.setShiming("不可二次实名");
            } else {
                excelPush.setShiming("支持人脸包赔");
            }
            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }


    public JSONObject yjwjmExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<YJWJMExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            YJWJMExcelPush excelPush = new YJWJMExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            if (StringUtils.isNotEmpty(goods.getF50())) {
                if (goods.getF50().equals("63666")) {
                    excelPush.setWyPayStatus("可注销");
                } else {
                    excelPush.setWyPayStatus("未注册");
                }
            } else {
                excelPush.setWyPayStatus("不可注销");
            }
            if (StringUtils.equals(goods.getCarrierName(), "网易手机")) {
                excelPush.setQudao("网易手机");
            } else {
                excelPush.setQudao("网易邮箱");
            }

            String f23 = goods.getF23();
            if (StringUtils.isNotEmpty(f23) && StringUtils.equals(f23, "60774")) {
                excelPush.setIsBind("已绑定");
            } else {
                excelPush.setIsBind("未绑定");
            }
            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;

    }

    public JSONObject aqtwExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<AQTWExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            AQTWExcelPush excelPush = new AQTWExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            String systemName = (goods.getSystemName() + goods.getCarrierName()).toLowerCase();
            if (StringUtils.equals("安卓qq", systemName)) {
                excelPush.setGroupResource("安卓QQ");
            } else if (StringUtils.equals("安卓微信", systemName)) {
                excelPush.setGroupResource("安卓微信");
            } else if (StringUtils.equals("苹果qq", systemName)) {
                excelPush.setGroupResource("苹果QQ");
            } else if (StringUtils.equals("苹果微信", systemName)) {
                excelPush.setGroupResource("苹果微信");
            } else {
                excelPush.setGroupResource("国际服");
            }
            String f3 = goods.getF3();
            if (StringUtils.equals(f3, "62980")) {
                excelPush.setShiming("可二次实名");
            } else if (StringUtils.equals(f3, "62981")) {
                excelPush.setShiming("不可二次实名");
            } else {
                excelPush.setShiming("支持人脸包赔");
            }

            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject sjzxdExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<SJZXDExcelPush> resultList = new ArrayList<>();
        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            SJZXDExcelPush excelPush = new SJZXDExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            String systemName = (goods.getSystemName() + goods.getCarrierName()).toLowerCase();
            if (StringUtils.isNotEmpty(systemName) && systemName.contains("微信")) {
                excelPush.setLoginType("微信登录");
            } else {
                excelPush.setLoginType("QQ登录");
            }
            String f7 = goods.getF7();
            if (StringUtils.isEmpty(f7)) {
                excelPush.setShiming("不可二次实名");
            } else if (StringUtils.equals(f7, "63944")) {
                excelPush.setShiming("可二次实名");
            } else if (StringUtils.equals(f7, "63945")) {
                excelPush.setShiming("支持人脸包赔");
            } else {
                excelPush.setShiming("不可二次实名");
            }

            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    public JSONObject smzhMExcelPushList(List<GoodsInfoAndAttrValueDto> goodsInfos, String gameName, SalePartner salePartner) {
        JSONObject gameMap = new JSONObject();
        List<SMZHMExcelPush> resultList = new ArrayList<>();
        GameAttribute attribute = new GameAttribute();
        attribute.setGameId(19L);
        List<GameAttribute> gameAttributes = gameAttributeService.selectGameAttributeList(attribute);
        Map<Long, String> attributeMap = gameAttributes.stream().collect(Collectors.toMap(s -> s.getId(), s -> s.getFieldName()));


        for (GoodsInfoAndAttrValueDto goods : goodsInfos) {
            SMZHMExcelPush excelPush = new SMZHMExcelPush();

            excelPush.setAccountNumber(goods.getAccountNumber());
            excelPush.setPassword(goods.getAccountPassword());
            excelPush.setPrice(goods.getPrice());
            excelPush.setRemark("");
            excelPush.setGoodsId(String.valueOf(goods.getId()));//商家商品id
            excelPush.setGoodsIdCode(String.valueOf(goods.getId())); // 上架商品编号

            String systemName = (goods.getSystemName() + goods.getCarrierName()).toLowerCase();
            if (StringUtils.isNotEmpty(systemName)) {
                if (StringUtils.equals(systemName, "安卓QQ")) {
                    excelPush.setQudao("安卓QQ");
                } else if (StringUtils.equals(systemName, "安卓微信")) {
                    excelPush.setQudao("安卓微信");
                } else if (StringUtils.equals(systemName, "苹果QQ")) {
                    excelPush.setQudao("苹果QQ");
                } else {
                    excelPush.setQudao("苹果微信");
                }
            }
            String f3 = goods.getF3();
            if (StringUtils.isEmpty(f3)) {
                excelPush.setShiming("不可二次实名");
            } else if (StringUtils.equals(f3, "64719")) {
                excelPush.setShiming("可二次实名");
            } else if (StringUtils.equals(f3, "64721")) {
                excelPush.setShiming("支持人脸包赔");
            } else {
                excelPush.setShiming("不可二次实名");
            }
            String f6 = goods.getF6();
            if (StringUtils.isNotEmpty(f6)) {
                String duanwei = attributeMap.get(Long.valueOf(f6));
                if (StringUtils.equals(duanwei, "传奇战神")) {
                    duanwei = "传奇";
                }
                if (StringUtils.equals(duanwei, "铂金")) {
                    duanwei = "白金";
                }
                excelPush.setDuanwei(duanwei);
            }
            StringBuilder sb = new StringBuilder();
            if (StringUtils.isNotEmpty(goods.getF4())) {
                sb.append(",").append(goods.getF4());
            }
            if (StringUtils.isNotEmpty(goods.getF5())) {
                sb.append(",").append(goods.getF5());
            }
            if (StringUtils.isNotEmpty(goods.getF7())) {
                sb.append(",").append(goods.getF7());
            }
            if (StringUtils.isNotEmpty(goods.getF8())) {
                sb.append(",").append(goods.getF8());
            }
            if (StringUtils.isNotEmpty(goods.getF9())) {
                sb.append(",").append(goods.getF9());
            }
            if (StringUtils.isNotEmpty(goods.getF14())) {
                sb.append(",").append(goods.getF14());
            }
            if (StringUtils.isNotEmpty(sb)) {
                String chuanshuoStr = sb.substring(1);
                List<String> list = Arrays.asList(chuanshuoStr.split(","));
                List<String> collect = list.stream()
                        .filter(s -> StringUtils.isNotEmpty(s) && StringUtils.isNotEmpty(attributeMap.get(Long.valueOf(s))))
                        .map(s -> attributeMap.get(Long.valueOf(s)))
                        .collect(Collectors.toList());
                excelPush.setChuanshuowuqi(StringUtils.join(collect, ","));
            }
            resultList.add(excelPush);
            gameMap.put(String.valueOf(goods.getId()), JSONObject.toJSONString(excelPush));
        }
        log.info(JSONObject.toJSONString(resultList));
        JSONObject res = pangxieExcelUtils.impostPX(resultList, gameName, salePartner);
        res.put("gameMap", gameMap);
        return res;
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    private List<String> getGameAttributeCheckBox(Map<Long, String> paramMap, String ids) {
        if (StringUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        List<String> resultList = new ArrayList<>();

        List<String> attrList = Arrays.asList(ids.replace(" ", "").split(","));
        for (Long key : paramMap.keySet()) {

            if (attrList.contains(String.valueOf(key))) {
                resultList.add(paramMap.get(key));
            }
        }
        return resultList;
    }


}
